<template>
  <div class="public_main">
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>{{$t('sidebar.dataReport')}}</el-breadcrumb-item>
        <el-breadcrumb-item>{{$t('finance.crumbsOne')}}</el-breadcrumb-item>
        <el-breadcrumb-item>{{$t('finance.crumbsFour')}}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <!-- -------------搜索查询栏------------------------ -->
    <search 
			:searchData="searchData" 
			@search="search" 
			@putExcel="putExcel" 
			:searchRight="true"
			:outputRight="$store.state.common.permiss.reportlist.includes('export')"
    ></search>
    <!-- -------------表单显示栏------------------------ -->
    <!-- <div class="table" v-if="$store.state.common.permiss.includes('RIGHT_ACCOUNT_LENDING_LIST')"> -->
    <div class="table">
      <template>
        <el-table
          :data="tableData" 
          size="small" 
          :summary-method="getSummaries"
          v-loading="loadFlag">
          <el-table-column align="center" prop="strLoanTime" :label="$t('public.no58')" width="86">
          </el-table-column>
          <el-table-column align="center" prop="productAmount" :label="$t('public.no54')" >
            <template slot-scope="scope">
              <span v-if="scope.row.productAmount!==null&&scope.row.productAmount!==undefined&&scope.row.productAmount!==''">{{$store.getters.moneySplit(scope.row.productAmount)}}</span>
              <span v-else>{{$store.state.common.nullData}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="productPeriod" :label="$t('public.no31')">
          </el-table-column>
          <el-table-column align="center" prop="dayInterestRate" :label="$t('proManage.dayInterest')">
          </el-table-column>
          <el-table-column align="center" prop="feeRate" :label="$t('proManage.feeRate')">
          </el-table-column>
          <el-table-column align="center" prop="overdueInterestRate" :label="$t('proManage.overdueInterest')">
          </el-table-column>
          <el-table-column align="center" prop="loanCount" :label="$t('totalManage.lendingCount')" >
          </el-table-column>
          <el-table-column align="center" prop="loanAmount" :label="$t('totalManage.amount')" min-width="130">
          </el-table-column>
          <el-table-column align="center" prop="refundCount" :label="$t('totalManage.realReturnCount')" >
          </el-table-column>
          <el-table-column align="center" prop="needRefundPrincipal" :label="$t('totalManage.no2')" min-width="130">
          </el-table-column>
          <el-table-column align="center" prop="needRefundInterest" :label="$t('totalManage.no3')" min-width="130">
          </el-table-column>
          <el-table-column align="center" prop="needRefundOverdueInterest" :label="$t('totalManage.no4')" min-width="130">
          </el-table-column>
          <el-table-column align="center" prop="refundAmount" :label="$t('totalManage.no1')" min-width="130">
          </el-table-column>
          <el-table-column align="center" prop="couponAmount" :label="$t('new.no63')" >
          </el-table-column>
          <el-table-column align="center" prop="noRefundCount" :label="$t('totalManage.noReturnCount')" >
          </el-table-column>
          <el-table-column align="center" prop="noRefundPrincipal" :label="$t('totalManage.no5')" min-width="130">
          </el-table-column>
          <el-table-column align="center" prop="noRefundInterest" :label="$t('totalManage.no6')" min-width="130">
          </el-table-column>
          <el-table-column align="center" prop="noRefundOverdueInterest" :label="$t('totalManage.no7')" min-width="130">
          </el-table-column>
          <el-table-column align="center" prop="noRefundAmount" :label="$t('totalManage.no8')" min-width="130">
          </el-table-column>
        </el-table>
      </template>
    </div>
    <!-- ------------  分页显示栏  ------------------------ -->
    <el-row type="flex" justify="end">
      <div class="pages" >
        <el-pagination
          @current-change="handleCurrentChange"
          :current-page="pagination.current"
          layout="sizes, prev, pager, next, total,->"
          :page-sizes="pagination.pageSizeOptions"
          :page-size="pagination.pageSize"
          @size-change="handleSizeChange"
          :total="pagination.total">
        </el-pagination>
      </div>
    </el-row>
    <div class="foot"></div>

  </div>
</template>
<script>
import getApp from 'src/mixins/getApp.js';//获取app和aok
import getPayChannel from 'src/mixins/getPayChannel.js';//获取下拉通道
import putExcel from 'src/mixins/putExcel.js';//导出excel
export default {
  mixins:[getApp,getPayChannel,putExcel],
  data () {
    const searchData=[
      {//放款日期
        type: 'rangePicker',
        label: 'public.no58',
        attr: 'loanTime',
        value: [],
      },
      {
        type: 'select',
        label: 'public.appName',
        attr: 'appName',
        option: [],
        value: '',
        langFlag: false,
      },
      {
        type: 'select',
        label: 'public.appPackage',
        attr: 'appPackage',
        option: [],
        value: '',
        langFlag: false,
      },
      {
        type: 'select',
        label: 'finance.channel',
        attr: 'channel',
        option: [],
        value: '',
        langFlag: false,
      },
    ]
    return {
      flag: true,
      loadFlag: true,
      pagination: {
        pageSize: global.config.pageSize,
        pageSizeOptions: global.config.pageSizeOptions,
        current: 1,
        total: 0,
      },
      searchData:searchData,
      formInline: {},// 用户查询信息数据对应字段
      tableData: [],// 用户信息数据模拟
      tableData1:[],//表格统计数据
      putExcelUrl:this.$action.finance_reportexport
    }
  },
  methods: {
    handleSizeChange (val) {// 每页条数变化时操作
      this.pagination.pageSize = val;
      this.getTableData();
    },
    handleCurrentChange (val) { // 分页按钮点击操作
      this.pagination.current = val;
      this.getTableData();
    },
    search(search) { // 搜索
      this.formInline = {
        loanTimeBegin:search.loanTime?search.loanTime[0]:'',
        loanTimeEnd:search.loanTime?search.loanTime[1]:'',
        appName:search.appName,
        appPackage:search.appPackage,
        channel:search.channel
      };
      if (this.flag) {
        this.pagination.currentPage = 1;
        this.flag = false;
        this.getTableData();
      }
      
    },
    getTableData () { // 放款列表获取
      this.loadFlag = true;
      let option = {
        pageNum:this.pagination.current,
        pageSize:this.pagination.pageSize,
        param: {
          ...this.formInline
        }       
      }
      this.$axios.post(this.$action.finance_reportlist, option).then(res => {
        this.flag = true;
        if (res.code == 200) {
          this.tableData = res.data.list.list;
          this.tableData1 = res.data.total;
          this.pagination.total = res.data.list.total;
        }else{
          this.$globalMsg.error(res.message)
        }
        this.loadFlag = false;
      })
    },
    getSummaries() {
      if(!this.tableData1) return;
      const sums = [
        this.$t('public.addTotal'),
        '-',
        '-',
        '-',
        '-',
        '-',
        this.tableData1.loanCount,
        this.tableData1.loanAmount,
        this.tableData1.refundCount,
        this.tableData1.needRefundPrincipal,
        this.tableData1.needRefundInterest,
        this.tableData1.needRefundOverdueInterest,
        this.tableData1.refundAmount,
        this.tableData1.couponAmount,
        this.tableData1.noRefundCount,
        this.tableData1.noRefundPrincipal,
        this.tableData1.noRefundInterest,
        this.tableData1.noRefundOverdueInterest,
        this.tableData1.noRefundAmount,
      ];
      return sums;
    }
  },
  mounted () {
    this.getApp().then(app=>{
      this.searchData[1].option=app.appName;
      this.searchData[2].option=app.appPackage;
    })
    this.getPayChannel().then(arr=>{
      this.searchData[3].option=arr;
    })
    this.getTableData();
  }
}
</script>
<style scoped lang="scss"></style>
